<template>
  <el-form>
    <el-row :gutter="10" justify="start">
      <el-col :span="12">
        <el-form-item label="用户id">
          <el-input v-model="pingjia.yhid" placeholder="请输入用户编号"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="订单编号">
          <el-input v-model="pingjia.ddid" placeholder="请输入订单编号"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="10" justify="start">
      <el-col :span="12">
        <el-form-item label="评价内容">
          <el-input v-model="pingjia.pjnr" placeholder="请输入内容"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="评分">
          <el-rate v-model="pingjia.sjpf" show-score text-color="#ff9900" score-template="{value}">
          </el-rate>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="10" justify="start">
      <el-col :span="12">
        <el-form-item label="评价图片">
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove"
            :file-list="fileList"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="">
          <el-dialog v-model="dialogVisible">
            <img width="100%" :src="fileList[0].url" alt="">
          </el-dialog>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col>
        <div style="text-align: center;">
          <el-button type="success" @click="doSave">保存</el-button>
          <el-button @click="doCancel">取消</el-button>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script setup lang="ts">
import {ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";

//---------------------------- 自定义组件事件 -----------------------------
const emits = defineEmits(["closeDialog", "flushPage"]);

const pingjia = ref({
  yhid:'',
  ddid:'',
  pjnr:'',
  sjpf:'',
  pjtp:''
})


// -------------------------------保存----------------------------------
const doSave = async () => {
  const {data} = await axios.post('/api/pingjia', pingjia.value);
  console.log(data)
  if (data.code === 200) {
    emits("flushPage");				// 触发事件： 刷新页面
    emits("closeDialog");			// 触发事件：关闭 dialog
    ElMessage.success("操作成功！");
  } else {
    ElMessage.error("操作失败！");
  }
}


// -------------------------------取消----------------------------------
function doCancel() {
  emits("closeDialog");
}

</script>

<style scoped>

</style>